package com.ants.platform.weixin.service.impl;

import com.ants.platform.core.bean.Page;
import com.ants.platform.core.db.mybatis.MyBatisDAO;
import com.ants.platform.weixin.service.TestService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by liushun on 2016/8/9.
 */
@Service
@Transactional(readOnly = true)
public class TestServiceImpl implements TestService {


    @Autowired
    private MyBatisDAO _dao;

    @Cacheable("baseCache")
    public Page getList(int pageNum, int pageSize, String orderField, String orderDirection) {
        PageHelper.startPage(pageNum, pageSize);
        if(orderField!=null&&orderDirection!=null)
            PageHelper.orderBy(orderField+" "+orderDirection);
        List list = _dao.selectList("StudentMapper.getList");
        Page page = new Page(list);
        return page;
    }

    @Transactional
    public void testTx() {
        Map map0 = new HashMap();
        map0.put("id", 500001);
        map0.put("user_name", "15673196342");
        map0.put("password", "87654321");
        map0.put("alias", "ailis");
        map0.put("email", "358113099@qq.com");
        _dao.insert("StudentMapper.add", map0);

        Map map1 = new HashMap();
        map1.put("id", 500002);
        map1.put("user_name", "18673196342");
        map1.put("password", "87654321");
        map1.put("alias", "miswan");
        map1.put("email", "530774513@qq.com");
        _dao.insert("StudentMapper.add", map1);

    }

}
